using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpiritDuck : MonoBehaviour {

    Transform m_dave;

    [SerializeField]
    float m_speed = 15.0f;

    float m_currentSpeed;

    [SerializeField]
    float m_distance = 5;

    bool m_mustFollow;

    Vector3 m_target;

	// Use this for initialization
	void Start ()
    {
        m_dave = FindObjectOfType<Dave>().transform;
	}
	
	// Update is called once per frame
	void Update ()
    {


        if(m_mustFollow)
        {
            m_target = m_dave.position + (Vector3.up * 5);
            transform.position = Vector3.Lerp(transform.position, m_target, m_speed*Time.deltaTime);
            transform.LookAt(m_target);
            if (Vector3.Distance(transform.position, m_dave.position) < m_distance)
                m_mustFollow = false;

        }
		else if(Vector3.Distance(transform.position, m_dave.position) > m_distance)
        {
            m_currentSpeed = 0;
            m_mustFollow = true;
        }
	}
}
